package com.actionscriptclass
{
    import com.actionscriptclass.dataholder.IDataHolder;
    import com.actionscriptclass.state.IState;
    import com.actionscriptclass.state.SetState;
    import com.actionscriptclass.timer.TimerInvoker;
   
    import flash.events.Event;
    import flash.events.EventDispatcher;
	 
 
	public class MainTimer extends EventDispatcher implements IState
	{
		protected var _setState:SetState;
        protected var _invokerTimer:TimerInvoker;
	    protected var _dispach:EventDispatcher;
	    protected var _mainData:IDataHolder;
	 
		public function MainTimer()
		{
	        _dispach = new EventDispatcher();
	  		_invokerTimer = new TimerInvoker();
	  		_setState =  new SetState();
           	_setState.setTimer(_invokerTimer);
            _invokerTimer.addEventListener("IntervalEnd",intervalEnd);
		}
		
		public function loop( loopNumber:uint=1 ):void
		{
 			 _setState.loop(loopNumber)
		}
		
		public  function start():void
		{ 
		 _setState.start();
		 }
		
		public  function stop():void
		{
		 _setState.stop();
		}
		
		public  function pause():void
		{
		  _setState.pause();
		}
		
		 
		
	    protected  function intervalEnd(event:Event):void
		{
			stop();
			dispatchEvent(new Event("IntervalEnd"));
		}
    }
}